<template>
	<view class="container">
		<!-- 提现金额 -->
		<view class="confirmPayMoney">
			<text style="font-size: 24rpx;color: #666666;margin-bottom: 20rpx;">当前购物积分余额{{userInfo.incomes}}</text>
			<text class="title">充值金额</text>
			<view class="input_con">
				<text>¥</text>
				<input type="digit" :value="totalPrice" @input="payMoneyChange" placeholder="请输入充值金额" placeholder-style="font-size: 28rpx" maxlength='10' confirm-type='done'/>
			</view>
			<text style="color: red;font-size: 26rpx;" v-if="!totalPricePass">{{priceRule}}</text>
		</view>
		<!-- 提现按钮 -->
		<view class="confirm">
			<jc-button @click='confirmTap' style="margin-top: 100rpx" :width='690' title='确认充值' backgroundColor="#FC5E53"></jc-button>
		</view>
	</view>
</template>

<script>
	import {user} from '@/api/user.js'
	import {lessee} from '@/api/lessee.js'
	import {wallet} from '@/api/wallet.js'
	import {
		payway
	} from '@/api/payway.js'
	import {wxminiproPay} from '@/common/utils/wxminiproPay.js'
	export default{
		data() {
			return {
				userInfo:{},
				totalPrice: '',
				totalPricePass: true,
				priceRule: "请输入大于零的数字",
				payWayIndex:0,
				lastItem:{},
				paywayInfo: {},
				serviceChargeRate: 0,
				serviceCharge_min: 0,
				serviceCharge_max: 0,
				typeList: [
					{
						name: '支付宝',
						key: 'ali'
					},{
						name: '微信',
						key: 'wx'
					},{
						name: '银行卡',
						key: 'bank'
					}]
			}
		},
		onLoad() {
		},
		onShow() {
			this.getUserInfo()
		},
		methods:{
			getUserInfo() {
				user.getUserInfo().then(res => {
					if (res.data.code == 10000) {
						var userInfo = res.data.data
						// userInfo.incomesPass = this.$count.sub(userInfo.incomes, userInfo.incomesLocked)
						userInfo.bankInfo = userInfo.bankName + ' ' + userInfo.bankAccount
						this.userInfo = userInfo
						this.getItemById()
					}
				})
			},
			getItemById() {
				lessee.getItemById().then(res => {
					if (res.data.code == 10000) {
						this.serviceChargeRate = res.data.data.serviceChargeRate
						this.serviceCharge_min = res.data.data.serviceCharge_min
						this.serviceCharge_max = res.data.data.serviceCharge_max
					}
				})
			},
			//完善会员资料
			setMemberInfo(){
				this.$Router.push({
					name: 'updateBankInfo'
				})
			},
			//选择到账卡
			selecttOutMoneyCart(){
				
			},
			//确认提现金额
			payMoneyChange(e){
				var value = e.detail.value.replace(/\s/g, "")
				if(isNaN(value)){
					this.totalPricePass = false
				}else{
					this.totalPricePass = true
				}
				if(value){
					this.totalPrice = parseFloat(value)
				}else{
					this.totalPrice = 0
				}
			},
			//确认提现按钮
			confirmTap(){
				// if(!this.paywayInfo.id){
				// 	this.$show.showMessage('请选择收款账户')
				// 	return
				// }
				if(!this.totalPrice){
					this.$show.showMessage('请输入充值金额')
					return
				}
				let priceStr = String(this.totalPrice)
				var totalPriceList = priceStr.split('.')
				if(totalPriceList.length>2){
					this.$show.showMessage('输入金额格式不正确')
					return
				}
				if(totalPriceList.length==2 && totalPriceList[1].length>2){
					this.$show.showMessage('输入金额格式不正确，请保留小数点后两位')
					return
				}
				var that = this
			 	var params = {
					scene: 'recharge',
					// payway: 'wxpay',
					payway: 'lzpay',
					sendType: 'noSend',
					realPay: this.totalPrice,
					remark: '充值'
				}
				this.wxminiproPay(params)
			},
			wxminiproPay(params){
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				wxminiproPay(params).then(res => {
					uni.hideLoading()
					if(res.data.code == 10000){
						uni.showModal({
							content: '支付成功',
							confirmText: '确定',
							showCancel: false,
							complete(_res) {
								if(_res.confirm){
									uni.navigateBack()
								}
							}
						})
					}
				})
			},
			//获取默认提现方式
			findDefaultPayway(){
				let that = this
				payway.findDefaultPayway().then(res => {
					if(res.data.code == 10000){
						this.paywayInfo = res.data.data
					}
				})
			},
			selectPaywayTap(){
				this.$Router.push({
					name: 'paywayList',
					params: {
						fromWay: 'outMoney'
					}
				})
			},
			//选择提现方式回调
			selectPaywayInfoBack(e){
				console.log('选择地址回调', e)
				this.paywayInfo = JSON.parse(decodeURIComponent(e))
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container{
	}
	.paywayItem{
		margin-top: 20rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		background-color: #FFFFFF;
		padding: 30rpx 0rpx;
		padding-right: 20rpx;
		.center{
			width: 750rpx;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			.contactInfo{
				display: flex;
				flex-direction: row;
				align-items: center;
				.default{
					background-color: #FC5E53;
					color: #FFFFFF;
					font-size: 20rpx;
					width: 50rpx;
					height: 30rpx;
					margin-right: 10rpx;
					text-align: center;
					font-weight: bold;
				}
				text{
					margin-top: 10rpx;
				}
			}
			.paywayInfo{
				display: flex;
				flex-direction: column;
				align-items: flex-start;
			}
			.right{
				margin-right: 30rpx;
			}
		}
	}
	.payway_cont{
		background-color: #FFFFFF;
		margin-top: 30rpx;
		.content_item{
			display: flex;
			flex-direction: row;
			align-items: center;
			padding: 0 30px;
			.left{
				.isSelect{
					width: 36rpx;
					height: 36rpx;
					padding: 10rpx;
				}
			}
			.right{
				width: 100%;
				display: flex;
				flex-direction: column;
				margin-left: 20rpx;
				padding: 30rpx 0;
			}
			.bottomLine{
				border-bottom: 1px solid #EFEFEF
			}
		}
	}
	.confirmPayMoney{
		margin-top: 20rpx;
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		background-color: #FFFFFF;
		.title{
			font-size: 32rpx;
		}
		.input_con{
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 40rpx;
			// border-bottom: 1px #EFEFEF solid;
			text{
				margin-right: 20rpx;
				font-size: 44rpx;
				font-weight: bold;
			}
			input{
				width: 100%;
				font-size: 34rpx;
			}
		}
		text{
			
		}
	}
	.message{
		color: $st-color-primary;
		font-size: 22rpx;
		margin-top: 20rpx;
		padding: 0 20rpx;
	}
	.confirm{
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>
